package com.alan.sqlite.demo.controller;

import com.alan.sqlite.demo.entity.User;
import com.alan.sqlite.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author alan
 * @description:
 * @date 2021/4/27
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/add")
    @ResponseBody
    public User add(String name){
        User user = new User();
        user.setName(name);
        return userService.save(user);
    }
    @RequestMapping("/findAll")
    @ResponseBody
    public Iterable<User> findAll(){
        return userService.findAll();
    }

    @RequestMapping("/update")
    @ResponseBody
    public User update(String id,String name){
        User user = new User();
        user.setId(id);
        user.setName(name);
        return userService.save(user);
    }
}
